package com.bdqn.easybuy1.utils;

import com.alibaba.fastjson.JSONObject;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class PrintUtil {
    public static void write(Object result, HttpServletResponse response) {
        response.setContentType("text/html; charset=utf-8");
        String json = JSONObject.toJSONString(result);
        print(json, response);
    }

    private static void print(String msg, HttpServletResponse response) {
        PrintWriter writer = null;
        try {
            if (null != response) {
                writer = response.getWriter();
                writer.print(msg);
                writer.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            writer.close();
        }
    }
}
